package com.cn.demo.springboot.controller;

import java.util.ArrayList;
import java.util.Date;
import com.cn.demo.springboot.service.user.UserService;
import com.cn.demo.springboot.shiro.annotation.MenuEx;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cn.demo.springboot.entity.User;

@Controller()
@RequestMapping("/freemarker")
public class FreemarkerController {
	private final static Logger log = LoggerFactory.getLogger(FreemarkerController.class);
	@Autowired
	private UserService userService;
	@RequiresPermissions("freemarker/1")
	@MenuEx(code = "freemarker/1",name="freemarker/1权限",parentCd = "",listSort = 999)
	@RequestMapping("/1")
	public String a(ModelMap map) {
		log.debug("a");
		 User user = new User();
		 user.setAddress("address");
		 user.setBirthday(new Date());
		 user.setId(1);;
		 map.put("user", user);
		 ArrayList<User> arrayList = new ArrayList();
		 arrayList.add(user);
		 arrayList.add(user);
		 arrayList.add(user);
		 arrayList.add(user);
		 arrayList.add(user);
		 map.put("users", arrayList);
		return "freemarker";
	}
	@RequiresPermissions("freemarker/2")
	@MenuEx(code = "freemarker/2",name="freemarker/2权限",parentCd = "freemarker/1",listSort = 1)
	@RequestMapping("/2")
	public void add() {
		 User user = new User();
		 user.setAddress("address");
		 user.setBirthday(new Date());
		 user.setId(10002);;
		 userService.update(user);
	}
	
	@RequiresPermissions("freemarker/22")
	@MenuEx(code = "freemarker/22",name="freemarker/22权限",parentCd = "freemarker/1",listSort = 1)
	@RequestMapping("/22")
	public void addd() {
		 User user = new User();
		 user.setAddress("address");
		 user.setBirthday(new Date());
		 user.setId(10002);;
		 userService.update(user);
	}
	
	@RequiresPermissions("freemarker/3")
	@MenuEx(code = "freemarker/3",name="freemarker/3权限",parentCd = "freemarker/2",listSort = 11)
	@RequestMapping("/add1")
	public void add1() {
		 User user = new User();
		 user.setAddress("address");
		 user.setBirthday(new Date());
		 user.setId(10002);;
		 userService.update(user);
	}
	
	@RequiresPermissions("freemarker/33")
	@MenuEx(code = "freemarker/33",name="freemarker/33权限",parentCd = "freemarker/2",listSort = 11)
	@RequestMapping("/add2")
	public void add2() {
		 User user = new User();
		 user.setAddress("address");
		 user.setBirthday(new Date());
		 user.setId(10002);;
		 userService.update(user);
	}
}
